package cn.kduck.module.message.service.impl;

import cn.kduck.module.message.service.SmsMessageSender;
import cn.kduck.module.message.service.SmsMessageService;
import cn.kduck.module.message.service.sender.SenderParam;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

@Service
public class SmsMessageServiceImpl implements SmsMessageService, InitializingBean {

    @Autowired(required = false)
    private SmsMessageSender smsMessageSender;

    @Override
    public void sendMessage(String phoneNum,String templateCode,String... params) {
        SenderParam senderParam = new SenderParam(phoneNum,templateCode,params);
        smsMessageSender.sendMessage(senderParam);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        Assert.notNull(smsMessageSender,"未配置任何有效的短信发送对象SmsMessageSender");
    }
}
